//
//  MiaoSha_Vm.swift
//  Pods
//
//  Created by eme on 2017/4/10.
//
//

import RxSwift
import NetWorkCore
import SwiftyJSON
import UtilCore

/*
 owner:cy
 update:2017年02月20日11:47:29
 info: 秒杀vm
 */
class MiaoSha_Vm :Base_Vm {
    /// 表示正在刷新中
    let loading = ActivityIndicator()
    /*
     接收返回的数据
     */
    /// 返回首页数据
    let miaoShaList = PublishSubject<[MiaoShaModel]>()
    
    /*
     通用设置
     */
    init(refreshTriger: Observable<String>) {
        super.init()
        let refreshSubject = Observable.of(
            refreshTriger,
            reloadTrigger.withLatestFrom(refreshTriger))
            .merge()
        refreshSubject
            .map{HomePageApi.getistimebyone(id: $0)}
            .emeRequestApiForArray(MiaoShaModel.self,activityIndicator: loading)
            .subscribe(onNext: {[unowned self] (result) in
                switch result {
                case .success(let data):
                    self.miaoShaList.onNext(data)
                case .failure(let error):
                    self.error.onNext(error)
                }
            })
            .disposed(by: disposeBag)
        
    }
    
}
